// components/custom-promotion/index.js
Component({
    options: {
        styleIsolation: "shared"
    },
    /**
     * 组件的属性列表
     */
    properties: {
        show: {
            type: Boolean,
            value: false
        },
        options: {
            type: Array,
            value: []
        },
        optionslist: {
            type: Object,
            value: {}
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        isShow: false,
        active: 0,
        hashp: false,
        haspp: false,
        hasdp: false,
    },

    /**
     * 组件数据字段监听器，用于监听 properties 和 data 的变化
     */
    observers: {
        // 监听弹出层开启、关闭状态变更
        "show": function (e) {
            let that = this;
            that.setData({
                isShow: e
            })
            console.log(this.data.options)
        },
        "optionslist": function (e) {
            let that = this;
            // that.setData({
            //     isShow: e
            // })
            // this.setData({
            //     optionslist:this.data.optionslist
            // })
            
            console.log('optionslist==',this.data.optionslist)
        },
        'options': function(newVal, oldVal){
            if (newVal && newVal.length >0) {

                console.log(newVal)
                this.data.options.forEach(item => {
                    Object.assign(item,{
                        is_selected:true
                    })
                    if (item.activetype == '1') {
                        this.setData({
                            hasdp: true
                        })
                    }else if (item.activetype == '2') {
                        this.setData({
                            haspp: true
                        })
                    }else if (item.activetype == '3') {
                        this.setData({
                            hashp: true
                        })
                    }
                })
                
            }

        }
    },

    /**
     * 组件的方法列表
     */
    methods: {
        onConfirm(e) {
            console.log('e',e)
            this.triggerEvent('onConfirm', e)
        },
        /**
         * 促销选择回调函数方法
         * @param {*} e 
         */
        onCheckSelect(e) {
            const { index, value } = e.currentTarget.dataset
            this.setData({
                active: index
            })
            // this.triggerEvent('check', { id: index, name: value })
        },
        handleSelZp(e) {
            const { value,index } = e.currentTarget.dataset
            console.log("handleSelZp", value)

            this.data.options.forEach(item => {
                item.is_selected = 0
                console.log(item.id, value.id)
                if (item.id == value.id) {

                    item.is_selected = 1
                }
            })
            this.setData( {
                options: this.data.options
            })
            this.triggerEvent('cxcheck', value)

        }
    }
})
